package io.wins.vertx.entity;

import java.util.Date;

import io.vertx.codegen.annotations.DataObject;
import io.vertx.core.json.JsonObject;
import io.wins.vertx.utils.UUIDUtils;
import org.apache.commons.lang3.StringUtils;

@DataObject(generateConverter = true)
public class Purchase {
    private final String id;
    private final String sellNo;
    private String customerId;
    private String itemId;
    private int itemType;
    private String title;
    private String detail;
    private float price;
    private int count;
    private float total;
    private String payType;
    private String areaName;
    private String address;
    private int status;
    private long createdOn;
    private long updatedOn;

    public Purchase(final JsonObject json) {
        PurchaseConverter.fromJson(json, this);
        this.id = StringUtils.isEmpty(json.getString("id")) ?
            UUIDUtils.genId() : json.getString("id");
        final String flag = this.getItemType() == 0 ? "T":"G";
        this.sellNo = StringUtils.isEmpty(json.getString("sellNo")) ?
            String.valueOf(flag + new Date().getTime()) : json.getString("sellNo");
    }

    public JsonObject toJson() {
        final JsonObject json = new JsonObject();
        PurchaseConverter.toJson(this, json);
        return json;
    }

    public String getId() {
        return this.id;
    }

    public String getSellNo() {
        return this.sellNo;
    }

    public String getCustomerId() {
        return this.customerId;
    }

    public void setCustomerId(final String customerId) {
        this.customerId = customerId;
    }

    public String getItemId() {
        return this.itemId;
    }

    public void setItemId(final String itemId) {
        this.itemId = itemId;
    }

    public int getItemType() {
        return this.itemType;
    }

    public void setItemType(final int itemType) {
        this.itemType = itemType;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(final String title) {
        this.title = title;
    }

    public String getDetail() {
        return this.detail;
    }

    public void setDetail(final String detail) {
        this.detail = detail;
    }

    public float getPrice() {
        return this.price;
    }

    public void setPrice(final float price) {
        this.price = price;
    }

    public int getCount() {
        return this.count;
    }

    public void setCount(final int count) {
        this.count = count;
    }

    public float getTotal() {
        return this.total;
    }

    public void setTotal(final float total) {
        this.total = total;
    }

    public String getPayType() {
        return this.payType;
    }

    public void setPayType(final String payType) {
        this.payType = payType;
    }

    public String getAreaName() {
        return this.areaName;
    }

    public void setAreaName(final String areaName) {
        this.areaName = areaName;
    }

    public String getAddress() {
        return this.address;
    }

    public void setAddress(final String address) {
        this.address = address;
    }

    public int getStatus() {
        return this.status;
    }

    public void setStatus(final int status) {
        this.status = status;
    }

    public long getCreatedOn() {
        return this.createdOn;
    }

    public void setCreatedOn(final long createdOn) {
        this.createdOn = createdOn;
    }

    public long getUpdatedOn() {
        return this.updatedOn;
    }

    public void setUpdatedOn(final long updatedOn) {
        this.updatedOn = updatedOn;
    }
}
